//package io.github.novaframe.config;
//
//import io.github.novaframe.web.ExceptionJsonTranslator;
//import io.github.novaframe.web.mapper.JsonMapper;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.format.FormatterRegistry;
//import org.springframework.format.datetime.standard.DateTimeFormatterRegistrar;
//import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
//import org.springframework.web.cors.CorsConfiguration;
//import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
//import org.springframework.web.filter.CorsFilter;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
//
///**
// * Created by Locki on 8/26/2017.
// */
//@Configuration
//public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
//
//    private final Logger logger = LoggerFactory.getLogger(getClass());
//
//    private final NovaframeProperties novaframeProperties;
//
//    public WebMvcConfiguration(NovaframeProperties novaframeProperties) {
//        this.novaframeProperties = novaframeProperties;
//    }
//
//    @Bean
//    public JsonMapper jsonMapper() {
//        return new JsonMapper();
//    }
//
//    @Bean
//    public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
//        final MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
//        converter.setObjectMapper(jsonMapper().mapper());
//        return converter;
//    }
//
//    @Bean
//    public CorsFilter corsFilter() {
//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//        CorsConfiguration config = novaframeProperties.getCors();
//        if (config.getAllowedOrigins() != null && !config.getAllowedOrigins().isEmpty()) {
//            logger.debug("Registering CORS filter");
//            source.registerCorsConfiguration("/**", config);
//            source.registerCorsConfiguration("/api/**", config);
//            source.registerCorsConfiguration("/v2/api-docs", config);
//        }
//        return new CorsFilter(source);
//    }
//
//    @Bean
//    public ExceptionJsonTranslator exceptionTranslator() {
//        return new ExceptionJsonTranslator();
//    }
//
//    @Override
//    public void addFormatters(FormatterRegistry registry) {
//        DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
//        registrar.setUseIsoFormat(true);
//        registrar.registerFormatters(registry);
//    }
//
//}
